package com.crm.miaohe.controller.navigation;

import com.crm.miaohe.controller.PageResponse;
import com.crm.miaohe.controller.navigation.request.NavigationDeleteRequest;
import com.crm.miaohe.controller.navigation.request.NavigationRequest;
import com.crm.miaohe.controller.navigation.request.NavigationSearchRequest;
import com.crm.miaohe.model.TblNavigation;
import com.crm.miaohe.service.NavigationService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/api/erp/navigation")
public class NavigationController {

    private final NavigationService navigationService;

    public NavigationController(NavigationService navigationService) {
        this.navigationService = navigationService;
    }

    @PostMapping
    public ResponseEntity<Void> addNavigation(@RequestBody @Valid NavigationRequest request) {
        navigationService.addNavigation(request);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/list")
    public ResponseEntity<PageResponse<TblNavigation>> queryNavigation(@Valid NavigationSearchRequest request) {
        return ResponseEntity.ok(navigationService.queryNavigation(request));
    }

    @GetMapping("/{navigationId}")
    public ResponseEntity<TblNavigation> queryNavigation(@PathVariable Long navigationId) {
        return ResponseEntity.ok(navigationService.queryNavigation(navigationId));
    }

    @PutMapping
    public ResponseEntity<Void> updateNavigation(@RequestBody @Valid NavigationRequest request) {
        navigationService.updateNavigation(request);
        return ResponseEntity.ok().build();
    }

    @DeleteMapping("/{navigationId}")
    public ResponseEntity<Void> deleteNavigation(@PathVariable Long navigationId) {
        navigationService.delete(navigationId);
        return ResponseEntity.ok().build();
    }

    @PostMapping("/batch_delete")
    public ResponseEntity<Void> deleteNavigation(@RequestBody @Valid NavigationDeleteRequest request) {
        navigationService.delete(request.getNavigationIds());
        return ResponseEntity.ok().build();
    }

}
